package org.pfc.porlapatilla.services;

import java.util.List;

import org.pfc.porlapatilla.model.Category;
import org.pfc.porlapatilla.repositories.CategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * This service provides data management to CategoryController
 * 
 * @author jorgepolobermudez
 * 
 */
@Service
public class CategoryService {

    /**
     * The CategoryRepository instance.
     */
    @Autowired
    private CategoryRepository categoryRepository;
    
    /**
     * Find all stored categories
     * @return The list of all categories
     */
    public List<Category> findAll() {
	return categoryRepository.findAll();
    }

    /**
     * Find stored category by name.
     * 
     * @param name
     *            Category name.
     * @return The found category.
     */
    public Category findByName(String name) {
	return categoryRepository.findByName(name);
    }

    /**
     * Store a <strong>category</strong>.
     * 
     * @param category
     *            The <strong>category</strong> to store.
     * @return The stored <strong>category</strong> id.
     */
    public String store(Category category) {
	return categoryRepository.save(category).getId();
    }

}
